import tkinter as tk
from tkinter import messagebox
from db import db

class RegisterFunction:
    #注册界面按钮的功能
    def __init__(self, frame, fram):
        self.frame = frame
        self.fram = fram

    def function_register(self, username, password):
        self.username = username
        self.password = password
        if self.username == "" or self.password == "":
            tk.messagebox.showinfo("提示信息", "注册信息不完整,请填写完整")
            return
        db.create_json('users.json')
        db.json_read('users.json')
        t = db.json_load
        d = {'username': self.username, 'password': self.password}

        for i in t:
            if i['username'] == d['username']:
                tk.messagebox.showinfo("提示信息", "该用户已存在")
                return

        db.json_insert('users.json', d)
        tk.messagebox.showinfo("提示信息", "用户注册成功")

    def function_exit(self):
        self.frame.pack_forget()
        self.fram.pack()